package cn.edu.wdu.gaojie.reflection.homework1;

import java.lang.reflect.InvocationTargetException;

/**
 * @author gaojie  gao4433@qq.com
 * @Description
 * @date 2021/11/29 15:51
 * @since 1.8
 */
public class CustomerService {
    private UserService service;

    public void say() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
        // TODO
        // 1. 调用 service 的 randomString 方法，并得到返回值
        // 2. 将返回值输出到控制台
        // 要求：不允许使用 new 关键字，即：service = new UserService()

        //方法一：
        Class<?> U = Class.forName("cn.edu.wdu.gaojie.reflection.homework1.UserService");
        service = (UserService) U.newInstance();

        System.out.println(service.randomString());


    }
}
